<template>
  <el-dialog
    :title="form.id?(isDetail?'详情':'编辑'):'新增'"
    :visible.sync="dialogVisible"
    :before-close="close"
    width="40%"
  >
    <el-form :disabled="isDetail" label-width="100px">
      <el-form-item label="通知标题">
        <el-input v-model="form.name" size="mini" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="发送范围">
        <ClassifyTreeSelect
          @input="getBranchId"
          @getValue="getBranchNode"
          :value="form.scopeSending"
          size="mini"
        />
      </el-form-item>
      <el-form-item label="通知内容">
        <el-input v-model="form.contentNotification" type="textarea" :rows="3" size="mini" placeholder="请输入" />
      </el-form-item>
    </el-form>
    <span v-if="!isDetail" slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { add, edit } from '@/api/cadreBusiness/notice'
export default {
  data () {
    return {
      dialogVisible: false,
      form: {},
      isDetail: false
    }
  },
  methods: {
    open (row, isDetail) {
      this.isDetail = isDetail
      this.form = { ...row }
      this.dialogVisible = true
    },
    confirm () {
      let submitForm = add
      if (this.form.id) {
        submitForm = edit
      }
      if (!this.form.scopeSending) {
        this.form.scopeSending = 0
      }
      submitForm(this.form).then((res) => {
        this.$message.success('保存成功')
        this.$emit('getData')
        this.close()
      })
    },
    getBranchNode (node) {
      this.form.scopeSending = node?.id || null
      // this.queryParams.partyOrgName = node?.fullNamePartyOrg || null
    },
    getBranchId (id) {
      // console.log('id', id)
    },
    close () {
      this.form = {}
      this.dialogVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
  .titleStyle {
    font-weight: 600;
    height: 35px;
    line-height: 35px;
    padding-left: 10px;
    padding-right: 10px;
    margin-bottom: 8px;
    background-color: #d8eff9;
    display: flex;
    justify-content: space-between;
  }
  .upload-demo {
    display: inline-block !important;
    margin-left: 16px;
  }
</style>
